IceWarp WebMail Protocol Specification Draft 0.11b
Copyright (c) 2005 IceWarp Ltd. All rights reserved.

Overview
--------

WM consists of 2 main modules. The client module and server module.
WM client interface is more like a sw mail client rather than a web application.

Client and server modules communicate with each other over HTTP layer using XML packets.
Some functions require a direct HTTP interaction.

From the protocol point of view we can define 2 transports:

Pure HTTP
XML Over HTTP


Client & Server
---------------

The client takes care of all interface issues and sends protocol requests to the server.
The server responds with a result which can be a success or failure. The server has to
keep a record of all active sessions, check their expiration and handle the client requests.
Each request has to contain a session id because the communication is not based on permanent connections.
The server keeps directories with user messages and settings.


Pure HTTP
---------

Apart from the WM client loading there are specific functions that cannot be achieved
the XML way.

These are:

File management functions (uploading and downloading files)
JWChat module

There will be a script upload.html and download.html which take care of the file management routines.

upload.html?sessionid={sid}&accountid={aid}&folderid={fid}&filename={name}&delete={delete}
download.html?sessionid{sid}&accountid={aid}&folderid={fid}&itemid={iid}&partid={pid}

sessionid - requires an active session
accountid - account the file goes to
folderid - folder of the file. when composing the client generates a random folderid which will be used here
filename - the name of the file to save to
itemid - specifies the item
partid - part of the item to download
delete - Boolean if file is to be deleted

For uploading there will be a special hidden folder which will be deleted after each user login.
This file folder will have a second folder with the folderid so that the client can work with multiple attachment
session for one user simultaneously


XML Over HTTP
-------------

The rest of the WM protocol is based on XML which is very similar to the Jabber protocol. Basic functions of the protocol are

Authentication management
Account management
Folder management
Items management
Storage management
Message composing

Each function has a specific structure of the XML. There are 2 types of XML messages:

iq - All management functions
message - Message composing

All XML is case sensitive and all tag names and attributes are in lower case.


The structure of XML messages is as following:

<iq uid={id} sid={sid} type={type} [format={format}]><query xmlns={xmlns}>{management}</query></iq>

<message uid={id} sid={sid}>{message}</message>


Attributes:

uid - Each client request can have an id which will be supplied in the server's response
sid - Session ID. All requests have to have a valid session ID (except the authentication functions)

type - ("set" / "get" / "result" / "error")
A blank type equals to "get". Set stands for editing data on the server, get reads/queries data on the server.
Result and error are response types from the server. Result is a success response.

format - ("xml" / "json")
Specifies the format of the data returned from the server (thus this attribute is used only within requests
from client to server). If ommitted, "xml" type is used by default.

xmlns - Specifies the area we want to deal with


We shall define a few constants which will be used only in this document to save space and time:

{iq} = <iq sid={sid} type={type} [format={format}]><query xmlns={xmlns}>
{/iq} = </query></iq>
{iq/} = <iq sid={sid} type={type}><query xmlns={xmlns} /></iq>

IN  = {Client sends a request to server}
OUT = {Server responds to client request}

GET = requests with <iq type="get">{query}</iq>
SET = requests with <iq type="set">{query}</iq>

iq (info/query)
---------------

<iq uid={id} sid={sid} type={type} [format={format}]><query xmlns={xmlns}>{management}</query></iq>

Attributes:

xmlns -
Each iq message has to have a namespace which identifies a type of the message. Each type has a different purpose.


********************************************************************************

=======================
== [webmail:iq:auth] ==
=======================

Takes care about session logon and/or new account creation if enabled.

GET: Create a hashid request
----------------------------

*** IN ***
	<iq>
		<query xmlns="webmail:iq:auth">
			<method>RSA</method>
		</query>
	</iq>
		
*** OUT ***
	<iq type="result">
		<query xmlns="webmail:iq:auth">
			<hashid>1150363395</hashid>
			<method>RSA</method>
		</query>
	</iq>


SET: Create a logon request with the RSA password hash
------------------------------------------------------

*** IN ***
	<iq type="set">
		<query xmlns="webmail:iq:auth">
			<username>jakub</username>
			<digest>1234123afh154345</digest>
			<method>RSA</method>
		</query>
	</iq>
		
*** OUT ***
	<iq sid={sid} type="result">
		<query xmlns="webmail:iq:auth"/>
	<iq>


SET: Create a logon request without password hash
-------------------------------------------------

*** IN ***
	<iq type="set">
		<query xmlns="webmail:iq:auth">
			<username>jakub</username>
			<digest>password</digest>
		</query>
	</iq>
		
*** OUT ***
	<iq sid={sid} type="result">
		<query xmlns="webmail:iq:auth"/>
	<iq>


SET: Logout
-----------

*** IN ***
	<iq type="set" sid="{sid}">
		<query xmlns="webmail:iq:auth">
		</query>
	</iq>
		
*** OUT ***
	{iq/}


TAGS:
username - specifies the user to logon
hashid - specifies the id the RSA will be created with
method - specifies the digest method. Currently only RSA is supported
digest - the RSA hash (hashid + password)

ATTRIBUTES:
sid - Session id that is required to be used in each subsequent request


********************************************************************************

===========================
== [webmail:iq:accounts] ==
===========================

Provides the account management functions.

GET: Retrieve the list of accounts
----------------------------------

*** IN ***
	{iq}
	{/iq}
		
*** OUT ***
	{iq}
		<account uid={user@domain}>
			<protocol/>
			<username/>
			<password/>
			<server/>
			<port/>
		</account>
		...
	{/iq}
	

Set: Manipulates an account based on the account action.

SET: Create a new account
-------------------------

*** IN ***
	{iq}
		<account action="add">
			<email>user@domain</email>
			[<username>user</username>]
			[<password>password</password>]
			[<protocol>imap</protocol>]
			[<server>127.0.0.1</server>]
			[<port>143</port>]
		</account>
	{/iq}
		
*** OUT ***
	{iq/}
	

SET: Edit an account
----------------------

*** IN ***
	{iq}
		<account action="edit" uid={user@domain}>
			[<username>user</username>]
			[<password>password</password>]
			[<protocol>imap</protocol>]
			[<server>127.0.0.1</server>]
			[<port>143</port>]
		</account>
	{/iq}
		
*** OUT ***
	{iq/}
	

SET: Delete an account
----------------------

*** IN ***
	{iq}
		<account action="delete" uid={user@domain} />
	{/iq}
		
*** OUT ***
	{iq/}


SET: Synchronize the IMAP database with real structure of IMAP folders
----------------------------------------------------------------------

*** IN ***
	{iq}
		<account action="sync" uid={user@domain} />
	{/iq}
		
*** OUT ***
	{iq/}

SET : Test account specified in request
---------------------------------------

*** IN ***
	{iq}
		<account action="test">
			<email>{email}</email>
			<username>{username}</username>
			<password>{password}</password>
			<server>{server}</server>
			<port>{port}</port>
			<protocol>{protocol}</protocol>
		</account>
	{/iq}

*** OUT ***
	{iq}
		<result>true|false</result>
	{iq/}

ATTRIBUTES:
uid - Specifies the account id (usually the format is user@domain). The primary account has a blank id or at least the request for a blank id should be considered as the primary account.
action - ("delete" / "edit" / "add" / "sync"/ "test") - Account action

TAGS:
Any number and account specific tags can be specified here. The basic tags are:

protocol - ("pop3" / "imap") - Account type
username - username to logon
password - password to logon
server - IP address of the server or a hostname
port - port where the specified protocol run on the given server 
email - id of a new account (should be in format user@domain)


********************************************************************************

==========================
== [webmail:iq:folders] ==
==========================

Provides the folder management functions.

GET: Retrieve the list of folders of an account
-----------------------------------------------

*** IN ***
	{iq}
		<account uid={aid}/>
	{/iq}
		
*** OUT ***
	{iq}
		<account uid={aid}>
			<folder uid={fid}>
				<name>Inbox</name>
				<type>I</type>
				<total>250</total>
				<recent>12</recent>
				<rights>rwmd</rights
				[<sync>1</sync>]
				[<parent/>]
			</folder>
			...
		</account>
	{/iq}


Set: Manipulates folders based on the folder action

SET: Create a new folder
------------------------

*** IN ***
	{iq}
		<account uid={aid}>
			<folder action="add">
				<name>Inbox/My Emails</name>
				[<type>I</type>]
			</folder>
		</account>
	{/iq}
		
*** OUT ***
	{iq/}


SET: Edit a folder
------------------

*** IN ***
	{iq}
		<account uid={aid}>
			<folder action="edit" uid={fid}>
				<name>newname</name>
				<subscribed>0|1</subscribed>
			</folder>
		</account>
	{/iq}
		
*** OUT ***
	{iq/}


SET: Delete a folder
--------------------

*** IN ***
	{iq}
		<account uid={aid}>
			<folder action="delete" uid={fid} />
		</account>
	{/iq}
		
*** OUT ***
	{iq/}



SET: Mark all messages in a (mail)folder as read
------------------------------------------------

*** IN ***
	{iq}
		<account uid={aid}>
			<folder action="markasread" uid={fid} />
		</account>
	{/iq}
		
*** OUT ***
	{iq/}

ATTRIBUTES:
uid - folder id
action - ("edit" / "delete" / "add" / "markasread")

TAGS:
name - A visible lable
sync - Folder subscription (Mail)
subscribed - Folder subscription (Mail)
type - ("mail" / "M" / contact" / "C" / "task" / "T" / "note" / "N" / "event" / "E" / "journal" / "J")
parent - parent folder id
total - Specifies number of items in folder
recent - Unread or recent items
rights - "rwmd" 
	r	READ
 	w	WRITE
	m	MODIFY
	d	DELETE 


********************************************************************************

========================
== [webmail:iq:items] ==
========================

Provides the functions for all items / objects management. 
Items can be messages and groupware objects.

GET: Get the list of items in a folder
--------------------------------------

*** IN ***
	{iq}
		<account uid={aid}>
			<folder uid={fid} />
		</account>
	{/iq}
		
*** OUT ***
	{iq}
		<account uid={aid}>
			<folder uid={fid} recent="{recent}" count="{count}">
				<item uid={iid}>
					<values>
						<from/>
						<to/>
						<cc/>
						<bcc/>
						<subject/>
						<date>unixtimestamp</date>
						<flag>00000000</flag>
						<text>text part</text>
						<html>&lt;html/&gt;&lt;/html&gt;</html>
						<attachments/> - see bottom of this section to read more about item attachments
					</values>
				</item>
				...				
			</folder>
		</account>
	{/iq}


GET: Get only some values of items in a folder according to a filter condition
------------------------------------------------------------------------------

*** IN ***
	{iq}
		<account uid={aid}>
			<folder uid={fid}>
				<item>
					<filter>
						{filter}
					</filter>
					<values>
						<from/>
						<to/>
					</values>
				</item>				
			</folder>
		</account>
	{/iq}
		
*** OUT ***
	{iq}
		<account uid={aid}>
			<folder uid={fid} recent="{recent}" count="{count}">
				<item uid={iid}>
					<values>
						<from/>
						<to/>
					</values>
				</item>
				...				
			</folder>
		</account>
	{/iq}


GET: Get item that is attached to another item
----------------------------------------------
Request defines original item by {aid}, {fid} and {iid} and its attachment specification {atid}.
Response contains attached item (ie. another item that has been attached to original item via 'link').

*** IN ***
	{iq}
		<account uid={aid}>
			<folder uid={fid}>
				<item uid={iid} atid={atid} />
			</folder>
		</account>
	{/iq}
		
*** OUT ***
	{iq}
		<account uid={at_aid}>
			<folder uid={at_fid} recent="{recent}" count="{count}">
				<item uid={at_iid}>
					<values>
						...
					</values>
					...
				</item>
			</folder>
		</account>
	{/iq}


Set: Manipulates items based on the item action

SET: Create a new item
----------------------

*** IN ***
	{iq}
		<account uid={aid}>
			<folder uid={fid}>
				<item action="add">
					<values>
					  <!--Events-->
						<evntitle/>
						[<evngrp_id/>]
						[<evnrcr_id/>]
						[<evn_editcounter/>]
						[<evnnote/>]
						[<evnlocation/>]
						[<evnsharetype/>]
						[<evntimezone/>]
						[<evntype/>]
						[<evnstatus/>]
						[<evnstartdate>unixtimestamp</evnstartdate>]
						[<evnstarttime/>]
						[<evnenddate>unixtimestamp</evnstartdate>]
						[<evnendtime/>]
						[<evn_created/>]
						[<evn_modified/>]
						[<evnpriority/>]
						[<evncomplete/>]
						[<evnorganizer/>]
						[<evncontact/>]
						[<evncolor/>]
						<!--Contacts-->
						[<itmfolder/>
            <itmsharetype/>
            <itmcategory/>
            <itmclass/>
            <itmtitle/>
            <itmfirstname/>
            <itmmiddlename/>
            <itmsurname/>
            <itmsuffix/>
            <itmjobtitle/>
            <itmcompany/>
            <itmclassifyas/>
            <itmdescription/>
            <itmofficelocation/>
            <itmgender/>
            <itmprofession/>
            <itmdepartment/>
            <itmnickname/>
            <itmbdate/>
            <itmspouse/>
            <itmanniversary/>
            <itminternetfreebusy/>
            <itmassistantname/>
            <itmmanagername/>]
					</values>
					<!-- Addons -->
					[<recurrences>
						<recurrence>
							<values>
								<rcrtitle/>
								<rcrdayrepetition/>
								<rcrdayofweeknumber/>
								<rcrweekrepetition/>
								<rcrweekofmonthnumber/>
								<rcrmonthrepetition/>
								<rcrmonthofyearnumber/>
								<rcryearrepetition/>
								<rcrenddate/>
							</values>
						</recurrence>
					</recurrences>]
					[<reminders>
						<reminder>
							<values>
                <rmntitle/>
                <rmndaysbefore/>
                <rmnhoursbefore/>
                <rmnminutesbefore/>
                <rmnactiontype/>
                <rmnactionvalue/>
							</values>
						</reminder>
						<reminder>...</reminder>
					</reminders>]
					[<contacts>
						<contact>
							<values>
                <cntemail/>
                <cntcontactname/>
                <cntrole/>
                <cntstatus/>
                <cntrsvp/>
                <cntexpect/>
							</values>
						</contact>
						<contact>...</contact>
					</contacts>]
          [<note>NoteText</note>]		
          [<locations>
            <location>
              <values>
                <lcttype/>
                <lctselected/>
                <lctdescription/>
                <lctwebpage/>
                <lctemail1/>
                <lctemail2/>
                <lctemail3/>
                <lctstreet/>
                <lctcity/>
                <lctstate/>
                <lctcountry/>
                <lctzip/>
              </values>
              <phones>
                <phone>
                  <values>
                    <phntype/>
                    <phnnumber/>
                    <phndescription/>
                  </values>
                </phone>
                <phone>..</phone>
              </phones>
            </location>
            <location>...</location>
          </locations>]
          [<attachments/>] - see bottom of this section to read more about item attachments
				</item>
			</folder>
		</account>
	{/iq}
		
*** OUT ***
	{iq/}


SET: Edit an item
-----------------

*** IN ***
	{iq}
		<account uid={aid}>
			<folder uid={fid}>
				<item uid={iid} action="edit">
					<values>
						<subnode/>
						...
					</values>
					<addons>
				</item>
			</folder>
		</account>
	{/iq}
	
Editing GW Addons
-----------------
EVENTS
======
Reminder,Recurrence,Contact
<item uid="{iid}">
  <values>Values to be edited in item</values>
  <reminders>
    <reminder uid="{rmn_id}" />               =>Deletes addon - {rmn_id} is specified, no values are specified
    

    <reminder uid="{rmn_id}">
      <values>
        <rmntitle>Editedtitle</rmntitle>      =>Edits addon, column rmntitle - {rmn_id} is specified, some of the values as well
      </values>
    </reminder> 

 
    <reminder>
      <values>NewReminderValues</values>      =>Creates new adddon(reminder) - no {rmn_id} is specified, values are specified
    </reminder>
  </reminders>
</item>

Note
<item uid="{iid}">
  <values>Values to be edited in item</values>
  <note/>                                     =>Delete note
  <note>NewNote</note>                        =>Edit or Add note
</item>


CONTACTS
========
Location
<item uid="{iid}">
  <values>Values to be edited in item</values>
  <locations>
    <location uid="{lct_id}">                 =>Same as reminders, etc...
      <values></values>
      <phones>
        <phone>
          <values>PhoneValues</values>        =>!!! recursively handled addon (ie. similar behavior as above)
        </phone>
      </phones>
    </location>
  </locations>
</item>

Certificate
<item uid="{iid}">
  <values>Values to be edited in item</values>
  <certificate/>                                     =>Delete certificate
  <certificate>NewCert</certificate>                 =>Edit or Add certificate
</item>

		
*** OUT ***
	{iq/}

	
SET: Delete an item
-------------------

*** IN ***
	{iq}
		<account uid={aid}>
			<folder uid={fid}>
				<item uid={iid} action="delete" />
			</folder>
		</account>
	{/iq}
		
*** OUT ***
	{iq/}


SET: Move an item to a different folder
---------------------------------------

*** IN ***
	{iq}
		<account uid={aid}>
			<folder uid={fid}>
				<item uid={iid} action="move">
					<folder>{fid}</folder>
					[<account>{aid}</account>]
				</item>
			</folder>
		</account>
	{/iq}
		
*** OUT ***
	{iq/}
	
SET: Redirect an email item
---------------------------

*** IN ***
	{iq}
		<account uid={aid}>
			<folder uid={fid}>
				<item uid={iid} action="redirect">
					<to />
					<distrib>
						<account>
							<folder>
								<to/>
								...
							</folder>
						</accounts>
					</distrib>
				</item>
			</folder>
		</account>
	{/iq}


ATTRIBUTES:
uid - Item id
action - ("edit" / "delete" / "add" / "move" / "copy" )
	- move - lets you move an item from a folder to another folder of the same type.

TAGS:
filter - A blank filter stands for all items in a folder. If a filter is defined, only those items that match the filter are listed.
	The structure of the filter follows:
		<filter>
			[<sql/>]
			[<interval/>]
			[<offset/>]
			[<limit/>]
			[<order_by/>]
		</filter>
	
	<sql> node stands for the WHERE part of a SQL statement
		The reason for SQL is that groupware items are all in a DB and the easiest way to access them is to specify the SQL WHERE clausule.
		Example:
		1) subject like 'spam'
		2) from = 'jakub@icewarp.com'
		3) id = 1564ewe564654
	<interval> node defines FROM-TO dates (in unixtimestamp format) of a time interval to be shown  
		Example:
		1) 1150301185-1150301200
	<limit> node defines the number of items to be listed (in format OFFSET,LIMIT)
		Example:
		1) 31,10
	<order_by>Set sorting parameters
		Example: EvnTitle,EvnCreationDate [DESC]
			

values - Specifies all values of the item. Each item has different values. In the GET request you may specify the values you want the server to return.
	If no values are specified all values will be returned. As for the GW, the values refer to the fields name in the GW database. As for messages, the 
	values refer to headers or message parts.
	Messages can also have an attachments tag with the list of attachments, their ids and names.

MessageItem/mailbody values:
----------------------------
	<text/> tag contains parsed text part of messagebody including all enclosed text/plain boundaries in UTF8
	<html/> tag contains parsed html part of messagebody including all enclosed text/html boundaries in UTF8

MessageItem/attachments:
------------------------

*** OUT ***
	<attachments>
		<attachment uid={id} >
			<values>
				<size/>
				<name/>
				<type/>
			</values>
		</attachment>
	</attachments>

*** IN ***
	<attachments>
		<attachment>
			<values>
				<class>item|file|attachment</class>
				<type>normal|embedded</type>
				<fullpath/>
			</values>
		</attachment>
	</attachments>

GroupwareItem/attachments:
--------------------------

*** OUT ***
	<attachments>
		<attachment uid={aid}/>
			<values>
				<attdesc/> - the only editable item for already existing gw attachments
				<atttype/>
				<attsize/>
				<atttime/>
			</values>
		</attachment>
	</attachments>

*** IN ***
	<attachments>
		<attachment>
			<values>
				<class>item|file|url|itemlink</class>
				<fullpath/>
				<description/>
			</values>
		</attachment>
	</attachments>
	
Attributes:
type - ("normal" / "groupware")
       Normal type is an ordinary attachment waiting in the files folder
       Groupware stands for a groupware item (contact, event etc.)
folder - For normal type this is the id of file folder (the same logic as for message attachments). For groupware type this is the original message folder defined by accountid|folderid.
item - For normal type this is the id of the attachment in the file folder. For groupware type this is the id of the item/message.

Tags:
fullpath - path to the item to be attached - see "class" tag explanation below for more details
class - specifies the type of the attachment and type of the content of the fullpath tag:
		"file" - a standard file is being attached. 'fullpath' contains 'folder/file' specification of already uploaded file (see Uploading Files as Attachments section below for more details)
		"item" - another gw item (or another message) is being attached. 'fullpath' contains 'account/folder/item' specification
		"itemlink" - link to another gw item is stored (links to messages are not supported). 'fullpath' is the same as for the "item" class
		"attachment" - attachment of another message is being attached. 'fullpath' contains 'account/folder/item/partID' specification
		"url" - an URL is being attached. 'fullpath' contains URL
description - is used only when attaching to a groupware item. contains user defined description of the item
type - is used only when attaching to a mail item. distinguishes whether the attachment will be attached "normally" or as an "embedded" attachment


Uploading Files as Attachments: 
-------------------------------
All attachments should be uploaded via upload.php script. Client may specify ID of destination folder where the file should be uploaded.
If no ID is specified, server creates new folder and returns its ID to the client so that the client may use this ID for further file uploads.
Server always returns file ID assigned to the just uploaded file so that client may use this ID when sending request to attach files to an item.

********************************************************************************

===========================
== [webmail:iq:freebusy] ==
===========================

Provides the busy view for specified user.

GET: Retrive user status
------------------------

*** IN ***
	{iq}
		<user email={email}/>
	{/iq}
		
*** OUT ***
	{iq}
		<user email={email}>
			<item date={date} time={time} status={status} />
		</user>
	{/iq}


ATTRIBUTES:
email - user account for the query
status - ( "busy" / "tentative" / "free" )


********************************************************************************

===============================
== [webmail:iq:spellchecker] ==
===============================

This namespace provides spellchecking capabilities.

GET: Client send plain text with specified dictionary, server response with all unknown words
---------------------------------------------------------------------------------------------

*** IN ***
	{iq}
		<check uid={id}>
			<text>plain text</text>
		</check>
	{/iq}
		
*** OUT ***
	{iq}
		<check uid={id}>
			<word>word</word>
			...
		</check>
	{/iq}


GET: Dtto, but server's response contains also suggested words 
--------------------------------------------------------------

*** IN ***
	{iq}
		<check uid={id}>
			<text>plain text</text>
			<suggest />
		</check>
	{/iq}
		
*** OUT ***
	{iq}
		<check uid={id}>
			<word>word</word>
			...
			<suggest word={orig_word}>
				<word>suggestedWord</word>
				...
			</suggest>
			...
		</check>
	{/iq}


GET: Request for suggested words
--------------------------------

*** IN ***
	{iq}
		<dictionary uid={id}>
			<suggest word={originalWord}/>
			...
		</dictionary>
	{/iq}
		
*** OUT ***
	{iq}
		<dictionary uid={id}>
			<suggest word={orig_word}>
				<word>suggestedWord</word>
				...
			</suggest>
			...
		</dictionary>
	{/iq}
	

TAGS:   
<suggest/>  - tag is optional, if it's present then response contains suggestions
	if not there are just unknown words in <word/> tags and client have to ask server 
	for suggestion in separate queries.


SET: Add new words to the user dictionary
-----------------------------------------

All new words are stored in custom.dic file in current userdir. This file is used for all spellcheck IDs!

*** IN ***
	{iq}
		<dictionary uid={id}>
			<add>word</add>
			...
		</check>
	{/iq}
		
*** OUT ***
	{iq}
		<dictionary uid={id} />
	{/iq}

   
********************************************************************************

======================================================================
== [webmail:iq:private] / [webmail:iq:public] / [webmail:iq:domain] ==
======================================================================

This namespace provides storage capabilities. By storage we understand a space the WM client can store 
small amount of data, particularly settings. The data stored can be XML or any data. For more details
about XML data storages, please refer to settings_restrictions.txt file in _project documentation folder.

private name space is used for user related settings and data storage - this is used by webmail client most often.
public name space is used for server settings common to all users. Only administrator can access these.
domain name space is used for server settings common to users of a domain. Only domain administrator can access these.

Storage is divided into several resources. In one request one or more resources can be accessed.
Some resources are "well-known" for server - such resource is always a XML file, server understands its
structure. On the other hand, other resources than "well-known" can be used and server just stores the data
for future usage. List of "well-known" resources is presented at the end of this section.


GET: Retrieve the resource data
-------------------------------

*** IN ***
	{iq}
		<resources>
			<{resource_name}/>
			...
		</resources>
	{/iq}
		
*** OUT ***
	{iq}
		<resources>
			<{resource_name} [useraccess={restriction} [domainadminaccess={restriction}]] [access={restriction}]>
				<item [useraccess={restriction} [domainadminaccess={restriction}]] [access={restriction}]>
					<{key} [useraccess={restriction} [domainadminaccess={restriction}]] [access={restriction}]>{value}</{key}>
					...
				</item>
				...
			</{resource_name}>
			...
		</resources>
	{/iq}
	

SET: Set data to resource
-------------------------

*** IN ***
	{iq}
		<resources>
			<{resource_name} [useraccess={restriction} [domainadminaccess={restriction}]] [access={restriction}]>
				<item [useraccess={restriction} [domainadminaccess={restriction}]] [access={restriction}]>
					<{key} [useraccess={restriction} [domainadminaccess={restriction}]] [access={restriction}]>{value}</{key}>
					...
				</item>
				...
			</{resource_name}>
			...
		</resources>
	{/iq}
		
*** OUT ***
	{iq/}


ATTRIBUTES:
useraccess/domainadminaccess - they are used for setting up access restrictions to user / domain administrator
	They are used in iq:public namespace only - an admin of a server can set both useraccess and domainadminaccess
	attributes while a domain admin can set useraccess attribute only (applying to users of his domain)
	Possible values are: 
		"full" (both read and write access)
		"view" (read only access, default value set by administrator is used)
		"none" (no access)
			
access - they are used to let the client know about restrictions set for a particular resource / item / key
	They are normally used in iq:private namespace, they can be used in iq:public namespace as well when a domain
	admin maintains global settings for his domain (just in case there is some "domainadminaccess" restriction).
	Possible values are "full" / "view" / "none" with the same meaning as in the domainadminaccess and useraccess
	attributes (when "view" mode is set, the default server value is always sent instead of user defined value)

TAGS:
{resource_name} - the name (ie. identification) of the resource

== "Well-known" resources ==
============================

settings
--------
Contains webmail settings in XML storage (both private and public files are used).

gw_groups
---------
Provides the access (listing and possible subscribing) to public GroupWare groups available to user.
An example of response:
<resources>
	<gw_groups>
		<item uid={gid} subscribed="true/false">
			<grp_id/>
			<grptitle/>
			<grplink/>
			<grpsharemode/>
			<grpdailyevents/>
			<grpdailyeventsemail/>
			<grpreminderemail/>
			<grpremindersdisabled/>
			<rights/>
		</item>
		...
	</gw_groups>
</resources>		

Subscription to a group (in SET request):
<resources>
	<gw_groups>
		<item uid={gid} subscribed="true/false" />
		...
	</gw_groups>
</resources>
       
gw_friends
----------
Contains settings of GW friends related to a user - zero or more items
<resources>
	<gw_friends>
		<item uid={fid}>
			<usr_id/>
			<usremail/> - can be either email address or [domain.com] for whole domain
			<usrcontactname/>
			<usrfriend/> - contains access rights of particular friend
		</item>
		...
	</gw_friends>
<resources>

gw_mygroup
----------
Contains all available settings of GW group related to the user (his only one default group) - exactly one item
<resources>	
	<gw_mygroup>
		<item uid={gid}>
			<grp_id/>
			<grptitle/>
			<grplink/>
			<grpsharemode/>
			<grpdailyevents/>
			<grpdailyeventsemail/>
			<grpreminderemail/>
			<grpremindersdisabled/>
			<rights/>
		</item>
	</gw_mygroup>
</resources>

gw_owner
--------
- owner section contains all available settings of particular user (from owner table) - exactly one item
An example of groupware settings:
<resources>
	<gw_owner>
		<item uid={oid}>
			<own_id/>
			<own_email/>
			<owndateformat/>
			<ownweekstart/>
			<owntimezone/>
			<owndaylightstart/>
			<owndaylightstop/>
			<owndaystart/>
			<owndayend/>
		</item>
	</gw_owner>
</resources>


********************************************************************************

==========================
== [webmail:iq:message] ==
==========================

SET: Create new message on server
---------------------------------

*** IN ***
	{iq}
		<message>
			<action>
				<send_as_email>true</send_as_email>
				<send_as_im>false</send_as_im>
				<smtp_relay>true|false</smtp_relay>
				<keep_attachments>false<keep_attachments>
				<html_body>true</html_body>
				[
				<save_to_folder>
					<account>{aid}</account>
					<folder>{fid}</folder>
					[<item>{iid}</item>]
				</save_to_folder>
				]
				[<encrypt>true</encrypt>]
				[<sign>true</sign>]
				[<auto_addressbook>true</auto_addressbook>]
			</action>
			
			<subject/>
			<from />
			<to />
			<cc />
			<bcc />
			<distrib>
				<account>
					<folder>
						<to>...</to><to>....</to><cc/><bcc/>...
					</folder>
						...
				</accounts>
				  ...
			</distrib>
			
			[
			<custom_headers>
				<header>X-Header1: value1</header>
				<header>X-Header2: value2</header>
				...
			</custom_headers>
			]
			
			<body/>
			
			[
			<attachments>
				<attachment>
					<values>
						<class/>
						<type/>
						<fullpath/>
					</values>
				</attachment>
			</attachments>
			]
			
		</message>
	{/iq}

afolderid = accountid|folderid when atype==message

*** OUT ***
	{iq/}
	
*** OUT (in case the <save_to_folder> is defined in the set query) ***	
	{iq}
		<message uid={id} />
	{/iq}
	

SET: Dial a SIP phone number
----------------------------

*** IN ***
	{iq}
		<dial>
			<phone/>
		</dial>
	{iq}

*** OUT ***
	{iq/}


GET: Get message for editing
----------------------------

*** IN ***
	{iq}
		<message uid={iid} folder={fid} account={aid} />
	{/iq}

*** OUT ***
	{iq}
		<message>
			<subject/>
			<from />
			<to />
			<cc />
			<bcc />
			
			[
			<custom_headers>
				<header>X-Header1: value1</header>
				<header>X-Header2: value2</header>
				...
			</<custom_headers>
			]
			
			<body/>
			<htmlbody/>
			
			<attachments>
				<attachment>
					<values>
						<class/>
						<type/>
						<fullpath/>
					</values>
				</attachment>
			</attachments>

		</message>
	{/iq}

ATTRIBUTES:
atype - ("normal" / "embedded" / "message")

TAGS:
action - specifies the particular action that should be taken by the server. send_as_email, send_as_im and keep_attachments are required, save_to_folder is optional. If keep_attachments is set to true, attachments won't be deleted from temporary folder (the user continues with editing the message) 
subject
from, to, cc, bcc - content of the headers in the new message
custom_headers - optional section
body - The body of the message
htmlbody - The HTML body of the message, htmlentities encoded. If presented, Body part is ignored (ie. Body part doesn't need to be presented in case of HTMLBody)
attachments - Specifies the message has attachments that should be sent along with the message
smtp_relay - if true send the email as SMTP relay with format @HOST:recipient

GET:
server strips out all attachments of specified item to a temporary folder (as if they were uploaded via upload.html module)
and returns their IDs in <attachments/> section.

Attachments:
Attachments need to be uploaded first using the upload.html HTTP module.
See webmail:iq:item specification for more details about enclosing attachments to a message.
